#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>

#define SIZE 512 
#define ZERO '\0'
#define SEP ' '

//getusername

const char* GetUserName()
{
  const char* name=getenv("USER");
  if(name==NULL) return "none";
  return name;
}
//gethostname

const char* GetHostName()
{
  const char* hostname=getenv("HOSTNAME");
  if(hostname==NULL) return "NONE";
  return hostname;
}
//getcwd

const char* GetCwd()
{
  const char* cwd=getenv("PWD");
  if(cwd==NULL) return"NONE";
  return cwd;
}

void MakeCommamdLineAndPrint()
{
  char line[SIZE];
  const char* username=GetUserName();
  const char* hostname=GetHostName();
  const char* cwd=GetCwd();

  snprintf(line,sizeof(line),"[%s@%s %s]: ",username,hostname,cwd);
  printf("%s",line);
  fflush(stdout);
}
 int GetuserCommand(char command[],size_t n)
{
  char * s=fgets(command,n,stdin);
  if(s==NULL) return -1;
  command[strlen(command)-1]=ZERO;
  return strlen(command);
}

int main()
{
  //printf("name: %s\n",GetUserName());
  
  // 1.commind line:
  MakeCommamdLineAndPrint();

  // 2.user command:
  char usercommand[SIZE];
  int n=GetuserCommand(usercommand,sizeof(usercommand));
  (void)n;

  // 3.



  printf("echo:%s\n",usercommand);
  
  return 0;
}




















